﻿#pragma once
#include "FilterInputStream.h"
#include "array/Array.hpp"

namespace yzrilyzr_io{
	ECLASS(BufferedInputStream, public FilterInputStream){
	private:
	yzrilyzr_array::ByteArray * buf=nullptr;
	yzrilyzr_array::ByteArray * getBufIfOpen();
	InputStream * getInIfOpen();
	u_index count=0;
	u_index pos=0;
	u_index markpos=-1;
	u_index marklimit=0;
	void fill();
	u_index read1(yzrilyzr_array::ByteArray & b, u_index off, u_index len);
	public:
	BufferedInputStream(InputStream & s);
	BufferedInputStream(InputStream & s, u_index size);
	~BufferedInputStream();
	int32_t read() override;
	u_index read(yzrilyzr_array::ByteArray & b) override;
	u_index read(yzrilyzr_array::ByteArray & b, u_index off, u_index len) override;
	u_index available() override;
	void close() override;
	};
}